package com.passer.toolbox.common.file.util;

import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONReader;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

public class ReadFileUtils {

    public static JSONObject readJsonFile(String path) throws IOException {
        JSONReader jsonReader = JSONReader.of(Files.newInputStream(Paths.get(path)), StandardCharsets.UTF_8);
        return jsonReader.read(JSONObject.class);
    }

    public static byte[] readBytes(String path) throws IOException {
        return Files.readAllBytes(Paths.get(path));
    }

    public static byte[] readBytes(File file) throws IOException {
        return readBytes(file.getPath());
    }
}
